package com.wang.service.impl;


import com.wang.bean.Result;
import com.wang.bean.Task;
import com.wang.mapper.TaskMapper;
import com.wang.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;


@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskMapper taskMapper;

    public List<Task> tasklog()
    {
        List<Task> list = taskMapper.tasklog();
        return list;
    }

    @Override
    public Result getvideodown(Task task) {
        Result re=new Result();
        Task task2 = findby(task);
        re.setCode("210");
        if(task2==null)
            re.setCode("201");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("1"))
            re.setCode("207");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("2"))
            re.setCode("208");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("3"))
            re.setCode("206");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("4"))
            re.setCode("211");
        re.setData(task2);
        return re;
    }


    public void taskdel(String id)
    {
        Task task=new Task ();
        task.setId(id);
        taskMapper.taskdel(task);
    }

    public List<Task> findAll() {
        List<Task> list = taskMapper.findAll();
        return list;
    }

    public void inserttask(Task task){
        task.setTaskstatus("1");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        task.setUsertime(df.format(new Date()));
        taskMapper.inserttask(task);
    }

    public Task  findby(Task task)
    {
        taskMapper.updatestatus(task);
        Task  ta=  taskMapper.findby(task);
       // System.out.println("out1:"+ta.getOutmessage());
       // ta.setOutmessage(ta.getOutmessage().replaceAll("\\\\",""));
        //System.out.println("out2:"+ta.getOutmessage());
        return ta;
    }

    public Result getmessage(Task task)
    {
        Result re=new Result();
        re.setType("2");
        re.setCode("210");
        Task task2 = findby(task);
        if(task2==null)
            re.setCode("201");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("1"))
            re.setCode("104");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("2"))
            re.setCode("103");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("3"))
            re.setCode("200");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("4"))
            re.setCode("211");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("6"))
            re.setCode("212");
        if(task2.getTaskstatus()==null||task2.getTaskstatus().equals("7"))
            re.setCode("107");
        re.setData(task2);
        return re;
    }

}